package com.xjc.business.controller.schadmin;

import com.xjc.business.entity.vo.schadmin.SchDetailVo;
import com.xjc.business.service.SchoolsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 徐锦程
 * 时间:2025-01-26 15:18
 */
@RestController
@RequestMapping("/sch_admin/school")
public class SchoolController {

    @Autowired
    SchoolsService schoolsService;

    @GetMapping("/getSchoolName/{id}")
    public Result<String> getSchoolName(@PathVariable(value = "id",required = false) Integer id) {
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return Result.okWithData(schoolsService.getById(id).getSchoolName());
    }

    /**
     * 获取学校详情
     * @param id 学校id
     * @return 学校详情
     */
    @GetMapping("/detail/{id}")
    public Result<SchDetailVo> getSchoolInfo(@PathVariable(value = "id",required = false) Integer id) {
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return schoolsService.getSchoolInfo(id);
    }
}